package com.relytosoft.mizar.media.common.entity.pojo.request.btdl.common;

import cn.hutool.core.io.IoUtil;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

/**
 * @author wss
 * @version 1.0
 * @date 2022/5/16 16:19
 */
@ApiModel("比特大陆数据转换req")
public class BtdlConvertReq {

    protected static Logger log = LoggerFactory.getLogger(BtdlConvertReq.class);

    private static String JSON_PARSE_ERROR = "json解析异常";

    public static BtdlDataReq toDataReq(HttpServletRequest request) {
        ServletInputStream inputStream = null;
        try {
            inputStream = request.getInputStream();
            String s = IoUtil.readUtf8(inputStream);
            return JSON.parseObject(s, BtdlDataReq.class);
        } catch (IOException e) {
            log.error("{},--", JSON_PARSE_ERROR, e);
        }
        return null;
    }

    public static BtdlStatusReq toStatusReq(HttpServletRequest request) {
        ServletInputStream inputStream = null;
        try {
            inputStream = request.getInputStream();
            String s = IoUtil.readUtf8(inputStream);
            return JSON.parseObject(s, BtdlStatusReq.class);
        } catch (IOException e) {
            log.error("{},--", JSON_PARSE_ERROR, e);
        }
        return null;
    }

    public static List<BtdlFaceControlReq> toFaceControlReq(HttpServletRequest request) {
        ServletInputStream inputStream = null;
        try {
            inputStream = request.getInputStream();
            String s = IoUtil.readUtf8(inputStream);
            return JSON.parseArray(s, BtdlFaceControlReq.class);
        } catch (IOException e) {
            log.error("{},--", JSON_PARSE_ERROR, e);
        }
        return null;
    }

    public static BtdlStructureControlReq toStruControlReq(HttpServletRequest request) {
        ServletInputStream inputStream = null;
        try {
            inputStream = request.getInputStream();
            String s = IoUtil.readUtf8(inputStream);
            return JSON.parseObject(s, BtdlStructureControlReq.class);
        } catch (IOException e) {
            log.error("{},--", JSON_PARSE_ERROR, e);
        }
        return null;
    }

    public static BtdlBehaviorDataReq toBehaviorDataReq(HttpServletRequest request) {
        ServletInputStream inputStream = null;
        try {
            inputStream = request.getInputStream();
            String s = IoUtil.readUtf8(inputStream);
            return JSON.parseObject(s, BtdlBehaviorDataReq.class);
        } catch (IOException e) {
            log.error("{},--", JSON_PARSE_ERROR, e);
        }
        return null;
    }
}
